﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickGraph;
using GraphSharp.Controls;
using System.Drawing;
using PI_CS_Library.PicsNetwork_Information_Model;
using PI_CS_Library.Virtual_Network_Information_Model;
using PI_CS_Tools;

namespace PI_CS_GUI
{
    public class Topology : BidirectionalGraph<Topology.Node, Topology.Link>
    {
        public Dictionary<int, Topology.Node> _nodes = new Dictionary<int, Topology.Node>();
        public Dictionary<int, Topology.Link> _edges = new Dictionary<int, Topology.Link>();

        public Topology()
        {
            _nodes = new Dictionary<int, Node>();
            _edges = new Dictionary<int, Link>();
        }

        public class Node
        {
            public int Id = 0;
            public string Name;
            public bool Virtual;

            public Node()
            { }
            public Point Position;
            public Node(PicsMatrix _infoModelNode)
            {
                Id = _infoModelNode.Id.Number;
                Name = _infoModelNode.Name;
                Virtual = false;
                Position = new Point((int)(_infoModelNode.PositionX), (int)(_infoModelNode.PositionY));
            }

            public Node(Matrix _infoModelNode)
            {
                Id = _infoModelNode.Id.Number;
                Name = _infoModelNode.Name;
                Virtual = true;
                Position = new Point((int)(_infoModelNode.PositionX), (int)(_infoModelNode.PositionY));
            }

            public override string ToString()
            {
                return Name;
            }

        }

        public class Link : Edge<Node>
        {

            public int Capacity;
            public int MaxCapacity { get; private set; }
            public int Id { get; private set; }

            public Link(Topology.Node source, Topology.Node target, int capacity, int Id)
                : base(source, target)
            {
                this.Id = Id;
                this.Capacity = this.MaxCapacity = capacity;
            }

        }

        public override bool AddVertex(Topology.Node v)
        {
            if (base.AddVertex(v))
            {
                _nodes.Add(v.Id, v);
                return true;
            }
            return false;
        }

        public override bool AddEdge(Topology.Link e)
        {
            if (base.AddEdge(e))
            {
                _edges.Add(e.Id, e);
                return true;
            }
            else
                return false;
        }

    }

    public class TopologyLayout : GraphLayout<Topology.Node, Topology.Link, Topology> { }
}
